package com.atguigui.leetcode1;

import java.util.ArrayList;
import java.util.List;

/**
 * 6921. 按分隔符拆分字符串
 * Project: leetcode
 * Package: com.atguigui.leetcode1
 * Version: 1.0
 * <p>
 * Created by WJX on 2023/7/24 9:28
 */
public class P6921SplitStringsBySeparator {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("$easy$");
        list.add("$problem$");

        List<String> strings = new P6921SplitStringsBySeparator().splitWordsBySeparator(list, '$');

    }

    public List<String> splitWordsBySeparator(List<String> words, char separator) {
        ArrayList<String> ans = new ArrayList<>();

        for (String word : words) {
            int start = 0;
            for (int i = 0; i < word.length(); i++) {

                // 找到分割符号
                if (word.charAt(i) == separator) {
                    String s = word.substring(start, i);
                    if (!"".equals(s) && !" ".equals(s)) {
                        ans.add(s);
                        start = i + 1;
                    } else {
                        start = i + 1;
                    }
                }
            }
            String s = word.substring(start, word.length());
            if (!"".equals(s) && !" ".equals(s)) {
                ans.add(s);
            }

        }

        return ans;
    }
}
